package com.changgou;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Mono;

@SpringBootApplication
@EnableEurekaClient
public class GatewayWebApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayWebApplication.class,args);
    }

    /*
    KeyResolver指定限流的Key
     */
    @Bean(name = "ipKeyResolver")
    public KeyResolver UserKeyResolver(){

/*        return new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                String s = exchange.getRequest().getRemoteAddress().getHostString();
                System.out.println(s);
                return Mono.just(s);
            }
        };*/
//Mono是响应式编程层与层之间传递的对象，Mono.just就是初始化一个Mono对象
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostString());

    }

}
